Note: As of version 1.6.0.2, HTML forms have been superseded by GUI functions in Tiny Hexer Script
|
You can use graphical user interfaces in Tiny Hexer Script via HTML forms in the structure viewer.
|
If you want to use custom dialogs in Tiny Hexer Scripts (e.g. to let the user change script settings), you can display and evaluate HTML Forms in the structure viewer. The structure viewer usually escapes all html special characters (like < and >) so they are displayed as characters in the browser window. To write HTML tags into the browser window, use the ACCEPTTAGS and RAW properties of the special browser file. Then you can write HTML code into the browser window of the structure viewer (which is an instance of Internet Explorer).
In this HTML code you can use hyperlinks to let the script be executed at a specific LABEL using the syntax <a href="@labelname">.... When the user clicks such a link, the script is executed at the label labelname.
You can also use HTML forms to execute the script at a label labelname using the syntax <form method="post" action="https://@labelname">... (method must be "post" to allow Tiny Hexer to retrieve the form's parameters, the "https://" prefix in the action argument is optional, but without this the Internet Explorer control might show a warning about "Sending unencrypted data over the Internet" before the soubroutine is called). The form's parameters are available in the called script subroutine on the stack, use the POP command to retrieve them.
If a label in Tiny Hexer Script is called via a HTML form in the structure viewer, the form's parameters are stored on the stack in a specific layout: The first value on the stack is the name of the first parameter, the second value is the data of the first parameter, the third value is the name of the second parameter, the fourth value is the data of the second parameter and so on. Use the ARGC special variable to retrieve the amount of values on the stack. All values on the stack are of type TEXT.
You can avoid the fixed format of HTML forms in the structure viewer by
setting the RAW property to 1 and writing a complete HTML file to the
browser window (including <html>, <head> and <body>
structures). See the script "Extract strings.mps" in Tiny Hexer's
scripts subdirectory for a more sophisticated example.
= all scripts to be executed in the structure viewer must be marked with this option OPTION TARGET, STRUCTUREVIEWER = open the browser window and write the form VAR browser FILE browser = FILEOPEN('::browser', 'c') = do not escape html characters to allow html tags FILESETPROP browser, 'accepttags', 1 = use a HERE document to write the form FILEWRITE browser << <form method="post" action="https://@showformparams"> Enter your forename: <input name="forename" /> Enter your surname: <input name="surname" /> Enter your location: <input name="location" /> <hr> <button type="submit">Continue</button> </form> >> FILECLOSE browser END = now, if the user clicks the "Continue" button, the label = "showformparams" is called @@showformparams VAR fore TEXT sur TEXT loc TEXT name TEXT num SIGQWORD = retrieve the form's parameters num = ARGC := are there parameters on the stack? WHILE num > 0 POP name IF (name == 'forename') POP fore ELSE IF (name == 'surname') POP sur ELSE IF (name == 'location') POP loc ELSE ERROR ("Unknown parameter: "+name) ENDIF ENDIF ENDIF INC num,-2 ENDWHILE = welcome the user MSGBOX ("Hello "+fore+" "+sur+" from "+loc)
This script's output will look like this:
|